import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class seleniumHello {

    public static void main(String[] args) throws Exception {
        //设置chromedriver地址
        System.setProperty("webdriver.chrome.driver", "D:/Users/qiqiwang/chromedriver.exe");
        //声明一个新driver
        WebDriver driver = new ChromeDriver();
        //打开网址
        driver.get("https://www.baidu.com");
        Thread.sleep(2000);
        System.out.print("已打开网址");
        //找到搜索框
        WebElement searchBox = driver.findElement(By.id("kw"));
        searchBox.sendKeys("摩天营救");
        Thread.sleep(2000);
        searchBox.submit();
        WebElement clickResults = driver.findElement(By.linkText("摩天营救_百度百科"));
        clickResults.click();
        Thread.sleep(8000);
        //退出
        driver.quit();

    }
}
